.386
.model flat, stdcall
option casemap:none

include windows.inc
include kernel32.inc
include user32.inc

includelib kernel32.lib
includelib user32.lib

MAX_XYSTEPS             equ 50
DELAY_VALUE             equ 50
X_STEP_SIZE             equ 10
Y_SETP_SIZE             equ 9
X_START_SIZE            equ 20
Y_START_SIZE            equ 10

LMA_APLHA               equ 2
LMA_COLORKEY            equ 1
WS_EX_LAYERED           equ 80000h

.data
pSetLayeredWindowAttributes dd  ?
hUser32Module               dd  ?

kUSER32_Dll                 db  "user32.dll", 0
kSetLayeredWindowAttributes db	"SetLayeredWindowAttributes", 0

.code
;**************************************************************
DllEntry proc hInst:DWORD, dwReason:DWORD, dwReserved:DWORD
    mov eax, TRUE
    ret
DllEntry endp
;**************************************************************

;**************************************************************
TopXY proc x:DWORD, y:DWORD
    shr x, 1
    shr y, 1
    mov eax, x
    sub y, eax
    mov eax, y
    ret
TopXY endp
;**************************************************************

;**************************************************************
AnimateOpen proc hWnd:DWORD
    local rect:RECT
    local dwLoopCount:dword
    local dwScreenWidth:dword
    local dwScreenHeight:dword
    local dwWidth:dword
    local dwHeight:dword
    local dwLeft:dword
    local dwTop:dword
    invoke GetWindowRect, hWnd, addr rect
    mov dwWidth, X_START_SIZE
    mov dwHeight, Y_SETP_SIZE
    invoke GetSystemMetrics, SM_CXSCREEN
    mov dwScreenWidth, eax
    invoke TopXY, dwWidth, eax
    mov dwLeft, eax
    invoke GetSystemMetrics, SM_CYSCREEN
    mov dwScreenHeight, eax
    invoke TopXY, dwHeight, eax
    mov dwTop, eax
    mov dwLoopCount, MAX_XYSTEPS
ANTILOOP:
    invoke MoveWindow, hWnd, dwLeft, dwTop, dwWidth, dwHeight, FALSE
    invoke ShowWindow, hWnd, SW_SHOWNA
    invoke Sleep, DELAY_VALUE
    invoke ShowWindow, hWnd, SW_HIDE
    add dwWidth, X_STEP_SIZE
    add dwHeight, Y_SETP_SIZE
    invoke TopXY, dwWidth, dwScreenWidth
    mov dwLeft, eax
    invoke TopXY, dwHeight, dwScreenHeight
    mov dwTop, eax
    dec dwLoopCount
    jnz ANTILOOP
    mov eax, rect.left
    mov ecx, rect.right
    sub ecx, eax
    mov dwWidth, ecx
    mov eax, rect.top
    mov ecx, rect.bottom
    sub ecx, eax
    mov dwHeight, ecx
    invoke TopXY, dwWidth, dwScreenWidth
    mov dwWidth, eax
    invoke TopXY, dwHeight, dwScreenHeight
    mov dwHeight, eax
    invoke MoveWindow, hWnd, dwLeft, dwTop, dwWidth, dwHeight, TRUE
    invoke ShowWindow, hWnd, SW_SHOW
    ret
AnimateOpen endp
;**************************************************************

;**************************************************************
AnimateClose proc hWnd:DWORD
    local rect:RECT
    local dwLoopCount:dword
    local dwScreenWidth:dword
    local dwScreenHeight:dword
    local dwWidth:dword
    local dwHeight:dword
    local dwLeft:dword
    local dwTop:dword
    invoke ShowWindow, hWnd, SW_HIDE
    invoke GetWindowRect, hWnd, addr rect
    mov eax, rect.left
    mov ecx, rect.right
    sub ecx, eax
    mov dwWidth, ecx
    mov eax, rect.top
    mov ecx, rect.bottom
    sub ecx, eax
    mov dwHeight, ecx
    invoke GetSystemMetrics, SM_CXSCREEN
    mov dwScreenWidth, eax
    invoke TopXY, dwWidth, eax
    mov dwLeft, eax
    invoke GetSystemMetrics, SM_CYSCREEN
    mov dwScreenHeight, eax
    invoke TopXY, dwHeight, eax
    mov dwTop, eax
    mov dwLoopCount, MAX_XYSTEPS
ANTILOOP:
    invoke MoveWindow, hWnd, dwLeft, dwTop, dwWidth, dwHeight, FALSE
    invoke ShowWindow, hWnd, SW_SHOWNA
    invoke Sleep, DELAY_VALUE
    invoke ShowWindow, hWnd, SW_HIDE
    sub dwWidth, X_STEP_SIZE
    sub dwHeight, Y_START_SIZE
    invoke TopXY, dwWidth, dwScreenWidth
    mov dwLeft, eax
    invoke TopXY, dwHeight, dwScreenHeight
    mov dwTop, eax
    dec dwLoopCount
    jnz ANTILOOP
    ret
AnimateClose endp
;**************************************************************

;**************************************************************
FadeInOpen proc hWnd:DWORD
    local dwAlpha:dword
    invoke GetWindowLongA, hWnd, GWL_EXSTYLE
    or eax, WS_EX_LAYERED
    invoke SetWindowLongA, hWnd, GWL_EXSTYLE, eax
    .if hUser32Module==NULL
        invoke GetModuleHandleA, addr kUSER32_Dll
        mov hUser32Module, eax
    .endif
    .if hUser32Module==NULL
        ret
    .endif
    .if pSetLayeredWindowAttributes==NULL
        invoke GetProcAddress, hUser32Module, addr kSetLayeredWindowAttributes
        mov pSetLayeredWindowAttributes, eax
    .endif
    .if pSetLayeredWindowAttributes==NULL
        ret
    .endif
    push LMA_APLHA
    push 0
    push 0
    push hWnd
    call pSetLayeredWindowAttributes
    mov dwAlpha, 90
    invoke ShowWindow, hWnd, SW_SHOWNA
FADELOOP:
    push LMA_COLORKEY + LMA_APLHA
    push dwAlpha
    push dwAlpha
    push hWnd
    call pSetLayeredWindowAttributes
    invoke Sleep, DELAY_VALUE
    add dwAlpha, 15
    cmp dwAlpha, 255
    jne FADELOOP
    push LMA_APLHA
    push 255
    push 0
    push hWnd
    call pSetLayeredWindowAttributes
    ret
FadeInOpen endp
;**************************************************************

;**************************************************************
FadeOutClose proc hWnd:DWORD
    local dwAlpha:dword
    invoke GetWindowLongA, hWnd, GWL_EXSTYLE
    or eax, WS_EX_LAYERED
    invoke SetWindowLongA, hWnd, GWL_EXSTYLE, eax
    .if hUser32Module==NULL
        invoke GetModuleHandleA, addr kUSER32_Dll
        mov hUser32Module, eax
    .endif
    .if hUser32Module==NULL
        ret
    .endif
    .if pSetLayeredWindowAttributes==NULL
        invoke GetProcAddress, hUser32Module, addr kSetLayeredWindowAttributes
        mov pSetLayeredWindowAttributes, eax
    .endif
    .if pSetLayeredWindowAttributes==NULL
        ret
    .endif
    push LMA_APLHA
    push 255
    push 0
    push hWnd
    call pSetLayeredWindowAttributes
    mov dwAlpha, 255
ANTILOOP:
    push LMA_COLORKEY + LMA_ALPHA
    push dwAlpha
    push dwAlpha
    push hWnd
    call pSetLayeredWindowAttributes
    invoke Sleep, DELAY_VALUE
    sub dwAlpha, 15
    cmp dwAlpha, 0
    jne ANTILOOP
    ret
FadeOutClose endp
;**************************************************************

end DllEntry